package com.xuanxu.blogs.module.article.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xuanxu.blogs.module.article.entity.dao.ArticleClassifyIntermediateDao;
import com.xuanxu.blogs.module.article.entity.po.ArticleClassifyIntermediate;
import com.xuanxu.blogs.module.article.mapper.ArticleClassifyIntermediateMapper;
import com.xuanxu.blogs.module.article.service.ArticleClassifyIntermediateService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author XuanXu
 * @version 1.0
 * @date 2024-08-23 14:09
 */
@Service
@RequiredArgsConstructor
public class ArticleClassifyIntermediateServiceImpl implements ArticleClassifyIntermediateService {

    private final ArticleClassifyIntermediateMapper articleClassifyIntermediateMapper;

    @Override
    public List<ArticleClassifyIntermediateDao> selectArticleClassifyIntermediateByArticleClassifyId(List<Long> articleClassifyIdList) {
        if (articleClassifyIdList == null || articleClassifyIdList.isEmpty()) {
            return null;
        }

        LambdaQueryWrapper<ArticleClassifyIntermediate> articleClassifyIntermediateLambdaQueryWrapper = new LambdaQueryWrapper<ArticleClassifyIntermediate>();
        articleClassifyIntermediateLambdaQueryWrapper.in(ArticleClassifyIntermediate::getArticleClassifyId, articleClassifyIdList);
        List<ArticleClassifyIntermediate> articleClassifyIntermediateList = articleClassifyIntermediateMapper.selectList(articleClassifyIntermediateLambdaQueryWrapper);

        return BeanUtil.copyToList(articleClassifyIntermediateList, ArticleClassifyIntermediateDao.class);
    }

    @Override
    public List<ArticleClassifyIntermediateDao> selectArticleClassifyIntermediateByArticleId(Long articleId) {
        if (articleId == null) {
            return null;
        }
        LambdaQueryWrapper<ArticleClassifyIntermediate> articleClassifyIntermediateLambdaQueryWrapper = new LambdaQueryWrapper<>();
        articleClassifyIntermediateLambdaQueryWrapper.eq(ArticleClassifyIntermediate::getArticleId, articleId);
        List<ArticleClassifyIntermediate> articleClassifyIntermediateList = articleClassifyIntermediateMapper.selectList(articleClassifyIntermediateLambdaQueryWrapper);
        return BeanUtil.copyToList(articleClassifyIntermediateList, ArticleClassifyIntermediateDao.class);
    }
}
